
#include <stdio.h>
#include <string.h>

#define MAX_USERS 100
#define USERNAME_LENGTH 20
#define PASSWORD_LENGTH 20

typedef struct {
    char username[USERNAME_LENGTH];
    char password[PASSWORD_LENGTH];
} User;

User users[MAX_USERS];
int user_count = 0;

void register_user() {
    if (user_count >= MAX_USERS) {
        printf("用户数量已满，无法注册新用户。\n");
        return;
    }

    printf("请输入用户名: ");
    scanf("%s", users[user_count].username);

    printf("请输入密码: ");
    scanf("%s", users[user_count].password);

    user_count++;
    printf("注册成功！\n");
}

void login_user() {
    char username[USERNAME_LENGTH];
    char password[PASSWORD_LENGTH];

    printf("请输入用户名: ");
    scanf("%s", username);

    printf("请输入密码: ");
    scanf("%s", password);

    for (int i = 0; i < user_count; i++) {
        if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) {
            printf("登录成功！欢迎回来，%s。\n", username);
            return;
        }
    }

    printf("用户名或密码错误，登录失败。\n");
}

int main() {
    int choice;

    while (1) {
        printf("1. 注册\n");
        printf("2. 登录\n");
        printf("3. 退出\n");
        printf("请选择操作: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                register_user();
                break;
            case 2:
                login_user();
                break;
            case 3:
                printf("退出程序。\n");
                return 0;
            default:
                printf("无效的选择，请重新输入。\n");
        }
    }

    return 0;
}